package com.upic.serviceImpl;

import com.upic.po.jurisdiction.Role;
import com.upic.repository.RoleRepository;
import com.upic.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhubuqing on 2018/2/7.
 */
@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleRepository roleRepository;

    @Override
    public Role saveRole(Role role) {
        return roleRepository.save(role);
    }

    @Override
    public String deleteRole(long roleId) {
        roleRepository.delete(roleId);
        return "SUCCESS";
    }

    @Override
    public Page<Role> searchRole(Pageable pageable) {
        return roleRepository.findAll(pageable);
    }

    @Override
    public List<Role> searchRole() {
        return roleRepository.findAll();
    }

    @Override
    public Role findOne(long roleId) {
        return roleRepository.findOne(roleId);
    }

    @Override
    public Role updateRole(Role role) {
        return roleRepository.saveAndFlush(role);
    }
}
